from django.db import models
from datetime import datetime
from django.core.validators import validate_comma_separated_integer_list
from decimal import Decimal


#Create your models here.
class Users(models.Model):  # 继承父类(包含增删改查)
    authority_CHOICES = (
        (0, '普通用户'),
        (1, '院、校用户'),
        (2, '超级管理员')
    )
    id = models.CharField(primary_key=True,max_length=255,verbose_name='id',) #主键可省略不写
    username = models.TextField(verbose_name='昵称',null=True)
    password = models.CharField(max_length=255, verbose_name='用户密码')  # 见4.1各种属性
    authority = models.IntegerField(choices=authority_CHOICES, default=0, verbose_name='权限')
    classification = models.CharField(max_length=20, default='学生', verbose_name='用户所属类别')
    # open_id = models.CharField(primary_key=True,max_length=255,verbose_name='用户唯一ID')
    fans_num = models.IntegerField(default=0, verbose_name='粉丝数量')
    concern_num = models.IntegerField(default=0, verbose_name='关注人数')
    avatar_url = models.CharField(max_length=255,verbose_name='头像url')
    phone = models.CharField(max_length=11,verbose_name='手机号')
    token = models.CharField(max_length=255,verbose_name='token',null=True)
    hot = models.DecimalField(max_digits=6, decimal_places=1,verbose_name="热度", default=Decimal('0.1') )
    date = models.DateTimeField(verbose_name='入驻日期', default=datetime.now())
    tag = models.CharField(max_length=255, verbose_name="标签", default='学生', )
    introduction = models.TextField(verbose_name="简介", null=True)
    school = models.CharField(max_length=255,verbose_name='学校',default='华中师范大学')

    class Meta:
        db_table = 'Users'
        verbose_name = '用户表'  # 在admin里的显示
        verbose_name_plural = verbose_name  # 显示的复数名称

class UserInfo(models.Model):  # 继承父类(包含增删改查)
    user = models.ForeignKey(Users,verbose_name='open_id',on_delete=models.CASCADE)
    avatar = models.CharField(max_length=255,verbose_name='头像')
    fans_num = models.IntegerField(max_length=255,verbose_name='粉丝数量')
    concern_num = models.IntegerField(max_length=255,verbose_name='关注人数')
    hot = models.FloatField(max_length=255, verbose_name="热度", default=0.1)
    date = models.DateTimeField(verbose_name='入驻日期', default=datetime.now())
    tag = models.CharField(max_length=255, verbose_name="标签", default='学生', )
    introduction = models.TextField(verbose_name="简介", null=True)

    class Meta:
        db_table = 'UserInfo'
        verbose_name = '用户信息表'  # 在admin里的显示
        verbose_name_plural = verbose_name  # 显示的复数名称

# 定义悬赏任务模型类
class Tasks(models.Model):  # 继承Model的操作
    '''自定义表对应的Model类'''
    # 定义属性：默认主键自增id字段可不写
    status_CHOICES = (
        (-1, '草稿箱'),
        (0, '已发布未拼团'),
        (1, '已拼团未完成'),
        (2, '任务完成')
    )
    userID = models.CharField(verbose_name='发布者的ID',max_length=255)
    title = models.CharField(max_length=20, verbose_name='任务名')
    introduction = models.CharField(max_length=100, verbose_name='任务简介')
    accept_nums = models.IntegerField(verbose_name='任务所需人数')
    money=models.IntegerField(verbose_name='每个人获得的赏金',default=0)
    start_time=models.DateTimeField(verbose_name='开始的时间YYYY-MM-DD HH:mm:ss',blank=True,null=True)
    end_time=models.DateTimeField(verbose_name='结束时间',null=True)
    expect_time=models.DateTimeField(verbose_name='校园代跑的期望完成时间',null=True)
    label=models.CharField(max_length=50,verbose_name='物品标签',null=True)
    send_classification = models.IntegerField(max_length=20, default=1,verbose_name='跑腿任务还是悬赏任务')
    status = models.IntegerField(choices=status_CHOICES, verbose_name='状态0.正在悬赏1.组队完成2.活动完成')
    confirmID = models.CharField(null=True, max_length=20, verbose_name='任务的签到码')

    # hbook = models.ForeignKey(Users,on_delete=models.CASCADE,verbose_name='用户id') # 外健

    # # 定义默认输出格式
    # def __str__(self):
    #     # 定义每个对象的显示信息
    #     return self.hname

    # 自定义对应的表名，默认表名：myapp_stu
    class Meta:
        db_table = "Tasks"  # 对应数据库表中名字
        verbose_name = '悬赏任务表'  # 在admin里的显示
        verbose_name_plural = verbose_name  # 显示的复数名称

class UserConnection(models.Model):  # 继承父类(包含增删改查)
    userid = models.CharField(max_length=255,verbose_name='用户id',)
    concern_id = models.CharField(max_length=255,verbose_name='关注的人的id',null=True)
    fans_id = models.CharField(max_length=255, verbose_name='粉丝的id',null=True)
    class Meta:
        db_table = 'UserConnection'
        verbose_name = '用户信息表'  # 在admin里的显示
        verbose_name_plural = verbose_name  # 显示的复数名称